package com.zp.business.controller.hospitalizationNotice;

import com.zp.business.entity.hospitalizationNotice.bo.HospitalizationNoticeBo;
import com.zp.business.entity.hospitalizationNotice.vo.HospitalizationNoticeVo;
import com.zp.business.service.hospitalizationNotice.IHospitalizationNoticeService;
import com.zp.common.core.controller.BaseController;
import com.zp.common.core.entity.R;
import com.zp.common.core.validate.AddGroup;
import com.zp.common.core.validate.EditGroup;
import com.zp.common.excel.utils.ExcelUtil;
import com.zp.common.log.annotation.Log;
import com.zp.common.log.enums.BusinessType;
import com.zp.common.myBatis.core.page.PageQuery;
import com.zp.common.myBatis.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 住院通知单控制器
 * 前端访问路由地址为:/business/HospitalizationNotice
 *
 * @author zhang peng
 * @ date 2024-06-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/HospitalizationNotice")
public class HospitalizationNoticeController extends BaseController {

    private final IHospitalizationNoticeService iHospitalizationNoticeService;

    /**
     * 查询住院通知单列表 (分页)
     */
//    @SaCheckPermission("business:HospitalizationNotice:list")
    @GetMapping("/selectPage")
    public TableDataInfo<HospitalizationNoticeVo> selectPage(HospitalizationNoticeBo bo, PageQuery pageQuery) {
        return iHospitalizationNoticeService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询住院通知单列表 (不分页)
     */
//    @SaCheckPermission("business:HospitalizationNotice:list")
    @GetMapping("/list")
    public R<List<HospitalizationNoticeVo>> list(HospitalizationNoticeBo bo) {
        List<HospitalizationNoticeVo> list = iHospitalizationNoticeService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出住院通知单列表
     */
//    @SaCheckPermission("business:HospitalizationNotice:export")
    @Log(title = "住院通知单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HospitalizationNoticeBo bo, HttpServletResponse response) {
        List<HospitalizationNoticeVo> list = iHospitalizationNoticeService.queryList(bo);
        ExcelUtil.exportExcel(list, "住院通知单", HospitalizationNoticeVo.class, response);
    }

    /**
     * 获取住院通知单详细信息
     *
     * @param noticeId 主键
     */
//    @SaCheckPermission("business:HospitalizationNotice:list")
    @GetMapping("/{noticeId}")
    public R<HospitalizationNoticeVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable String noticeId) {
        return R.ok(iHospitalizationNoticeService.queryById(noticeId));
    }

    /**
     * 新增住院通知单
     */
//    @SaCheckPermission("business:HospitalizationNotice:add")
    @Log(title = "住院通知单", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HospitalizationNoticeBo bo) {
        return toAjax(iHospitalizationNoticeService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改住院通知单
     */
//    @SaCheckPermission("business:HospitalizationNotice:edit")
    @Log(title = "住院通知单", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HospitalizationNoticeBo bo) {
        return toAjax(iHospitalizationNoticeService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除住院通知单
     *
     * @param noticeIds 主键串
     */
//    @SaCheckPermission("business:HospitalizationNotice:remove")
    @Log(title = "住院通知单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{noticeIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable String[] noticeIds) {
        return toAjax(iHospitalizationNoticeService.deleteWithValidByIds(Arrays.asList(noticeIds), true) ? 1 : 0);
    }


    /**
     * 查询患者入院基本信息如果存在直接插patVisitIndex，不存在查patMasterIndex信息
     */
    @GetMapping("/getHosPatientInfo")
    public R<HospitalizationNoticeVo> getHosPatientInfo(HospitalizationNoticeBo bo) {
        HospitalizationNoticeVo hospitalizationNoticeVo = iHospitalizationNoticeService.getHosPatientInfo(bo);
        return R.ok(hospitalizationNoticeVo);
    }
}
